﻿
using BLL;
using Common;
using IBLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace WindowsFormsApp1.登录老师账号界面
{
    public partial class AddStudengts : Form
    {
        IFrStudentManage_IBLL frStudent=new FrStudentManage_BLL();
        public AddStudengts()
        {
            InitializeComponent();
            comboClass.DataSource = frStudent.SClass();
            comboClass.DisplayMember = "ClassName";
            comboClass.ValueMember = "ClassId";
        }
      
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Students_MD Students_MD = new Students_MD()
            {
                
                StudentName = txtName.Text,
                Gender = radioMan.Checked == true ? "男" : "女",
                Birthday = dtmBrithday.Value.ToString(),
                PhoneNumber = txtPhoneNum.Text,
                ClassId = (int)comboClass.SelectedValue,
                ClassName = comboClass.Text,
                StudentIdNo = txtStudentIdNo.Text,
                StudentAddress = txtAddress.Text??null,
                StuImage = pictureBox1.Image == null ? null : Common_Com.SerializeObjevtToString(pictureBox1.Image).ToString(),
            };
            //验证格式
            string Sinfo = verificationPassWrod_com.addVerify(Students_MD);
            if (Sinfo != null)
            {
                MessageBox.Show(Sinfo, "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }
            try
            {
                //提交
               int index= frStudent.AddSStudent(Students_MD);
                if (index==-1)
                {
                    MessageBox.Show("考生信息修改失败,请检查考生信息", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("考生信息修改失败 错误信息：" + ex.Message, "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }
           
            DialogResult result = MessageBox.Show("添加考生信息成功", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.Cancel)
            {
                this.Close();
            }
            else
            {
                txtName.Text = null;
                txtAddress.Text = null;
                txtStudentIdNo.Text = null;
                dtmBrithday.Value = DateTime.Now;
                txtPhoneNum.Text = null;
                comboClass.SelectedIndex = -1;
                radioMan.Checked = false;
                radioGirl.Checked = false;
                pictureBox1.Image = null;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|Windows Bitmap(*.bmp)|*.bmp|Windows Icon(*.ico)|*.ico|Graphics Interchange Format (*.gif)|(*.gif)|JPEG File Interchange Format (*.jpg)|*.jpg;*.jpeg|Portable Network Graphics (*.png)|*.png|Tag Image File Format (*.tif)|*.tif;*.tiff";
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
            }
        }
    }
}
